package com.utils.conmponentbase.base.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

import com.utils.conmponentbase.base.BaseTabEntity;

import java.util.List;

/**
 * MvvmDemo com.utils.conmponentbase.base
 * 2020-01-03 16:01
 */
public class BaseStaticFragmentAdapter extends FragmentStatePagerAdapter {
    private List<Fragment> mFragmentList;
    private List<BaseTabEntity> mTitle;

    public BaseStaticFragmentAdapter(@NonNull FragmentManager fm, List<Fragment> pFragmentList, List<BaseTabEntity> pTitle) {
        super(fm, FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
        mFragmentList = pFragmentList;
        mTitle = pTitle;
    }

    public BaseStaticFragmentAdapter(@NonNull FragmentManager fm, int behavior, List<Fragment> pFragmentList, List<BaseTabEntity> pTitle) {
        super(fm, behavior);
        mFragmentList = pFragmentList;
        mTitle = pTitle;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        if (null == mTitle || mTitle.size() <= 0) return null;
        return mTitle.get(position).getTitle();
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }
}
